﻿using System;
using System.IO;
using UnityEngine;

namespace UFrameWork
{
    public class FileLog
    {
        private string log = string.Empty;

        private string path = string.Empty;

        private ULogLevel level;

        /// <summary>
        /// 文件日志
        /// </summary>
        /// <param name="file">文件名称</param>
        public FileLog(string file,ULogLevel level = ULogLevel.Debug)
        {
            this.level = level;
            path = UnityFile.GetPath(file);
        }

        public void Write(object obj, ULogLevel level, string tag)
        {
            if (level < this.level) return;

            log = string.Format("[{0}]{1}-{2}:{3}\r\n",DateTime.Now.ToString("HH:mm:ss:fff"),level,tag,obj.ToString());

            File.AppendAllText(path, log);
        }
    }
}